package game.module.shop.dao;

import game.module.shop.bean.ShopEntity;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.ResultSetExtractor;
import org.springframework.stereotype.Repository;

@Repository
public class ShopDao {

	@Autowired
	private JdbcTemplate jdbcTemplate;

	public List<ShopEntity> getAllTemplate() {
		return jdbcTemplate.query("select * from shop_template", new ResultSetExtractor<List<ShopEntity>>() {
			@Override
			public List<ShopEntity> extractData(ResultSet rs) throws SQLException, DataAccessException {
				List<ShopEntity> shopEntities = new ArrayList<ShopEntity>();
				while (rs.next()) {
					ShopEntity shopEntity = new ShopEntity();
					shopEntity.setGoodmodelId(rs.getInt("good_model_id"));
					shopEntities.add(shopEntity);
				}
				return shopEntities;
			}
		});
	}

}
